//package com.uoko.plugins.es.impl;
//
//import com.uoko.plugins.es.ElasticsearchStrategy;
//import org.apache.http.HttpHost;
//import org.elasticsearch.action.delete.DeleteRequest;
//import org.elasticsearch.action.get.GetRequest;
//import org.elasticsearch.action.index.IndexRequest;
//import org.elasticsearch.action.search.SearchRequest;
//import org.elasticsearch.action.update.UpdateRequest;
//import org.elasticsearch.client.RestClient;
//import org.elasticsearch.client.RestHighLevelClient;
//
//import java.common.Objects;
//
///**
// * @Description ESHttpClient
// * @Author shanjing
// * @Create 2018/5/10-16:30
// * @Version 1.0.0
// */
//public abstract class ESHttpClient implements ElasticsearchStrategy{
//
//    private final static String  INDEX = "uoko";
//    private String ES_SCHEME_DEFAULT = "http";
//
//    protected RestHighLevelClient client;
//
//    /**
//     * 客户端初始化
//     */
//    public RestHighLevelClient ESHttpClient(String httpHost ,Integer httpPort){
//        return ESHttpClient(ES_SCHEME_DEFAULT,httpHost ,httpPort);
//    }
//
//    public RestHighLevelClient ESHttpClient(String httpScheme,String httpHost ,Integer httpPort){
////        RestHighLevelClient client = new RestHighLevelClient(
////                RestClient.builder(
////                        new HttpHost("localhost", 9200, "http"),
////                        new HttpHost("localhost", 9201, "http")));
////
//        if(Objects.nonNull(client))
//            return client;
//        else
//            client = new RestHighLevelClient(
//                    RestClient.builder(
//                            new HttpHost(httpHost, httpPort, httpScheme)
//                    ));
//        return client;
//    }
//
//    /**
//     * 创建新文档
//     * @param type 文档类型
//     * @param documentId  文档ID
//     * @return 返回IndexRequest 通过以下方式实现对象存储
//     *      request.source(jsonString, XContentType.JSON);
//     *      request.source(jsonMap);
//     *          XContentBuilder builder = XContentFactory.jsonBuilder();
//     *               builder.startObject();
//     *               {
//     *               builder.field("user", "kimchy");
//     *               builder.field("postDate", new Date());
//     *               builder.field("message", "trying out Elasticsearch");
//     *               }
//     *               builder.endObject();
//     *       request.source(builder)
//     */
//    protected IndexRequest putIndex(String type, String documentId){
//        return new IndexRequest(INDEX,type,documentId);
//    }
//
//    /**
//     * 获取创建的文档
//     * @param type
//     * @param documentId
//     * @return
//     */
//    protected GetRequest getRequest(String type, String documentId){
//        GetRequest getRequest = new GetRequest(INDEX,type,documentId);
//        return getRequest;
//    }
//
//    /**
//     * 修改文档
//     * @param type
//     * @param documentId
//     * @return  返回 UpdateRequest 通过以下方式实现对象存储
//     *      UpdateRequest request = new UpdateRequest("posts", "doc", "1");
//     *       String jsonString = "{" +
//     *       "\"updated\":\"2017-01-01\"," +
//     *       "\"reason\":\"daily update\"" +
//     *       "}";
//     *       request.doc(jsonString, XContentType.JSON);
//     *       request.doc(jsonMap);
//     *       request.doc(builder);
//     */
//    protected UpdateRequest pullRequest(String type, String documentId){
//        UpdateRequest updateRequest = new UpdateRequest(INDEX,type,documentId);
//        return updateRequest;
//    }
//
//    /**
//     * 删除文档
//     * @param type
//     * @param documentId
//     * @return
//     */
//    protected DeleteRequest delIndex(String type, String documentId){
//        DeleteRequest deleteRequest = new DeleteRequest(INDEX,type,documentId);
//        return deleteRequest;
//    }
//
//
//    protected SearchRequest searchRequest(String type){
//        SearchRequest searchRequest = new SearchRequest(INDEX);
//        return searchRequest;
//    }
//
//}
